<template>
	<el-card shadow="hover">
		<template v-slot:header>
			值班看板
			<span style="margin-left: 10px;font-size: 14px;font-weight: 200;cursor: pointer" :class="sortId==item.sortId?'avt':''" @click="getDutyListBySortId(item.sortId)" v-for="item in sortList" :key="item.sortId">{{item.sortName}}</span>
			<div style="float: right;display: inline-flex">
				<sc-icon style="cursor: pointer;width: 18px; margin-right: 10px;" @click="reLoadData" title="刷新"><el-icon-refresh-right/></sc-icon>
				<sc-icon style="cursor: pointer;width: 18px;" @click="getMoreData" title="全部"><el-icon-more-filled/></sc-icon>
			</div>
		</template>
		<div style="height: 210px;text-align: center;">
			<el-table :data="tableDataList" style="width: 100%" :show-header="false" @row-click="showRecord" class="customer-table">
			<el-table-column prop="dutyUserName" width="120">
				<template #default="scope">
					<div style="display: flex;">
						<el-avatar :src="scope.row.avatar" size="small"></el-avatar>
						<span style="position: absolute;margin-left: 30px;">{{scope.row.dutyUserName}}</span>
					</div>
				</template>
			</el-table-column>
				<el-table-column prop="title" width="200" align="center" :show-overflow-tooltip="true"></el-table-column>
			<el-table-column prop="beginTime" :show-overflow-tooltip="true">
				<template #default="scope">
					{{scope.row.beginTime.split(" ")[1]}}~{{scope.row.endTime.split(" ")[1]}}
				</template>
			</el-table-column>
			<el-table-column prop="tel" width="150" align="center"></el-table-column>
			</el-table>
		</div>
	</el-card>
	<recordDetails v-if="dialog.detailsSave" ref="detailsDialog" @closed="dialog.detailsSave=false"></recordDetails>
</template>

<script>
import recordDetails from '@/views/office/duty/create/details'
export default {
	components: {
		recordDetails,
	},
	data() {
		return {
			dialog: {
				detailsSave:false,
				supervisionSave:false,
			},
			sortId:'',
			sortList:[],
			tableDataList:[],
			timer:null
		}
	},
	created() {
		clearInterval(this.timer)
		this.timer = null
	},
	beforeUnmount() {
		clearInterval(this.timer);
		this.timer = null
	},
	mounted() {
		this.getDutySortListForSelect();
	},
	methods: {
		async getDutySortListForSelect(){
			var res = await this.$API.office.duty.getDutySortListForSelect.get();
			if (res.code == 200) {
				this.sortList = res.data
				if(res.data.length>0)
				{
					this.sortId = res.data[0].sortId;
				}
				this.reLoadData();
				this.setTimer();
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		reLoadData(){
			this.getDutyListBySortId(this.sortId);
		},
		getMoreData(){
			this.$nextTick(() => {
				this.$router.replace({
					path: '/office/duty/search',
				})
			})
		},
		async getDutyListBySortId(sortId){
			this.sortId = sortId;
			var res = await this.$API.office.duty.getDutyListBySortId.get({sortId:this.sortId});
			if (res.code == 200) {
				this.tableDataList = res.data
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		showRecord(row, event, column) {
			this.dialog.detailsSave = true
			this.$nextTick(() => {
				this.$refs.detailsDialog.open().setData(row)
			})
		},
		setTimer() {
			if(this.timer == null) {
				this.timer = setInterval( () => {
					this.reLoadData();
				}, this.$TOOL.data.get("MSG_TIME"))
			}
		},
	}
}
</script>
<style scoped>
.avt {
	border-bottom:2px solid red;
}
:deep(.el-table tr){
	cursor: pointer;
}
.customer-table th {
	border: none;
}
.customer-table td, .customer-table th.is-leaf {
	border: none;
}

.el-table--border, .el-table--group {
	border: none;
}

.customer-table thead tr th.is-leaf {
	border: 1px solid #EBEEF5;
	border-right: none;
}

.customer-table thead tr th:nth-last-of-type(2) {
	border-right: 1px solid #EBEEF5;
}

.el-table--border::after, .el-table--group::after {
	width: 0;
}

.customer-table::before {
	width: 0;
}

.customer-table .el-table__fixed-right::before, .el-table__fixed::before {
	width: 0;
}

.el-table--border th.gutter:last-of-type {
	border: 1px solid #EBEEF5;
	border-left: none;
}
</style>
